package beautiful.butterfly.drds.data_exchange.statistics;


import lombok.Getter;
import lombok.Setter;

public class SumPerfRecord4Print
{

    @Setter
    @Getter
    public long perfTimeTotal = 0;
    @Setter
    @Getter
    public long averageTime = 0;

    @Setter
    @Getter
    public long maxTime = 0;
    @Setter
    @Getter
    public int maxTaskId = -1;

    @Setter
    @Getter
    public int maxTaskGroupId = -1;
    @Setter
    @Getter
    public int totalCount = 0;
    @Setter
    @Getter
    public long recordsTotal = 0;
    @Setter
    @Getter
    public long sizesTotal = 0;
    @Setter
    @Getter
    public long averageRecords = 0;
    @Setter
    @Getter
    public long averageBytes = 0;
    @Setter
    @Getter
    public long maxRecord = 0;
    @Setter
    @Getter
    public long maxByte = 0;
    @Setter
    @Getter
    public int maxTaskId4Records = -1;
    @Setter
    @Getter
    public int maxTGID4Records = -1;

    public void add(RunningInfo runningInfo)
    {
        if (runningInfo == null)
        {
            return;
        }
        perfTimeTotal += runningInfo.get$nanoTime();
        if (runningInfo.get$nanoTime() >= maxTime)
        {
            maxTime = runningInfo.get$nanoTime();
            maxTaskId = runningInfo.getTaskId();
            maxTaskGroupId = runningInfo.getTaskGroupId();
        }

        recordsTotal += runningInfo.getCount();
        sizesTotal += runningInfo.getSize();
        if (runningInfo.getCount() >= maxRecord)
        {
            maxRecord = runningInfo.getCount();
            maxByte = runningInfo.getSize();
            maxTaskId4Records = runningInfo.getTaskId();
            maxTGID4Records = runningInfo.getTaskGroupId();
        }

        totalCount++;
    }


    public long getAverageTime()
    {
        if (totalCount > 0)
        {
            averageTime = perfTimeTotal / totalCount;
        }
        return averageTime;
    }


    public long getAverageRecords()
    {
        if (totalCount > 0)
        {
            averageRecords = recordsTotal / totalCount;
        }
        return averageRecords;
    }

    public long getAverageBytes()
    {
        if (totalCount > 0)
        {
            averageBytes = sizesTotal / totalCount;
        }
        return averageBytes;
    }


}
